package com.wwl.cms.utils.designModeTest.command;

/**
 * @author wwl
 * @version 1.0
 * @date 2021/9/9 15:27
 * @description:
 */
public class RemoteController {
    //开 按钮的命令组
    Command[] onCommands;
    Command[] offCommands;
    Command undoCommand;
    //构造器，完成对按钮初始化
    public RemoteController(){
        onCommands = new Command[5];
        offCommands = new Command[5];
        for (int i=0;i<5;i++){
            onCommands[i] = new NoCommand();
            offCommands[i] = new NoCommand();
        }
    }
    //给我们的按钮设置你需要的命令
    public void setCommand(int no,Command onCommand,Command offCommand){
        onCommands[no] = onCommand;
        offCommands[no] = offCommand;
    }

    //按下开按钮
    public void onButtonWasPushed(int no){
        //找到你按下的开的按钮
        onCommands[no].execute();
        undoCommand= onCommands[no];
    }

    public void offButtonWasPushed(int no){
        //找到你按下的开的按钮
        offCommands[no].execute();
        undoCommand= offCommands[no];
    }
    public void undoButtonWasPushed(){
        undoCommand.undo();
    }
}
